package com.sany.struts.action;

import java.io.PrintWriter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.sany.struts.form.PlanRetailerForm;
import com.sany.web.beans.RetailerBean;
import com.sany.web.beans.RetailerTypeBean;

public class PlanRetailerAction extends DispatchAction implements Serializable {
	private static final long serialVersionUID = 1L;
	public void getRetailerTypeList(ActionMapping mapping, ActionForm forms,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		RetailerTypeBean retailerTypeBean=new RetailerTypeBean();
		retailerTypeBean.setRetailerTypeId("1");
		retailerTypeBean.setRetailerTypeName("asd1");
		List retailerTypeList = new ArrayList();
		retailerTypeList.add(retailerTypeBean);
		RetailerTypeBean retailerTypeBean2=new RetailerTypeBean();
		retailerTypeBean2.setRetailerTypeId("2");
		retailerTypeBean2.setRetailerTypeName("asd2");
		retailerTypeList.add(retailerTypeBean2);
		PrintWriter out = response.getWriter();
	 //   ObjectMapper objectMapper =new ObjectMapper();
	   // JsonGenerator jsonGenerator= objectMapper.getJsonFactory().createJsonGenerator(out);
//	    jsonGenerator.writeObject(retailerTypeList);
	   // objectMapper.writeValue(out, planCreateForm);
		out.flush();
		out.close();
	}
	public ActionForward getRetailerList(ActionMapping mapping, ActionForm forms,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		PlanRetailerForm planRetailerForm=(PlanRetailerForm)forms;
	    String retailNo=planRetailerForm.getRetailNo();
		String retailName=planRetailerForm.getRetailName();
		String retailType=planRetailerForm.getRetailType();
		String city=planRetailerForm.getCity();
		System.out.println("retailNo:"+retailNo+"retailName:"+retailName+"retailType:"+retailType+"city:"+city);
		
		RetailerTypeBean retailerTypeBean=new RetailerTypeBean();
		retailerTypeBean.setRetailerTypeId("1");
		retailerTypeBean.setRetailerTypeName("asd1");
		List retailerTypeList = new ArrayList();
		retailerTypeList.add(retailerTypeBean);
		retailerTypeBean.setRetailerTypeId("2");
		retailerTypeBean.setRetailerTypeName("asd2");
		retailerTypeList.add(retailerTypeBean);
		planRetailerForm.setRetailerTypeList(retailerTypeList);
		List retailerList = new ArrayList();
		RetailerBean retailerBean=new RetailerBean();
		retailerBean.setAddr("addr1");
		retailerBean.setCity("city1");
		retailerBean.setLoop("loop1");
		retailerBean.setRetailName("retailName1");
		retailerBean.setRetailNo("retailNo1");
		retailerBean.setRetailType("retailType1");
		retailerList.add(retailerBean);
		RetailerBean retailerBean2=new RetailerBean();
		retailerBean2.setAddr("addr2");
		retailerBean2.setCity("city2");
		retailerBean2.setLoop("loop2");
		retailerBean2.setRetailName("retailName2");
		retailerBean2.setRetailNo("retailNo2");
		retailerBean2.setRetailType("retailType2");
		retailerList.add(retailerBean2);
		planRetailerForm.setRetailerList(retailerList);
		return mapping.findForward("retailerPop");
	}
}
